/**
* Created by wl
* 基金储备库-编辑投资案例信息
*/
<template>
    <div>
        <div class="ca-title">
            <div class="el-right">
                <el-button type="primary" size="small" @click="save">保存</el-button>
                <el-button @click="close" size="small">取消</el-button>
            </div>
            <el-form class="ca-table-add-reduce" :model="itemInfo">
                <el-table
                :data='itemInfo.fundData'
                @header-click="add"
                class="ca-table table_p_01 el-wid-100">
                    <el-table-column
                        label="项目名称"
                        prop="itemId"
                        align="center"
                        width="100px">
                        <template slot-scope="scope">
                            <el-input v-model="scope.row.itemId" :maxlength="100"></el-input>
                        </template>
                    </el-table-column>
                    <el-table-column
                        label="公司名称"
                        prop="company"
                        align="center"
                        width="100px">
                        <template slot-scope="scope">
                            <el-input v-model="scope.row.company" :maxlength="100"></el-input>
                        </template>
                    </el-table-column>
                    <el-table-column
                        prop="industry"
                        label="行业"
                        align="center"
                        width="80px">
                        <template slot-scope="scope">
                            <el-input v-model="scope.row.industry" :maxlength="100"></el-input>
                        </template>
                    </el-table-column>
                    <el-table-column
                        prop="investMoney"
                        label="投资金额</br>（万元）"
                        :render-header="renderTitle"
                        align="center"
                        width="100px"
                        >
                        <template slot-scope="scope">
                            <el-input type="number" v-model="scope.row.investMoney"></el-input>
                        </template>
                    </el-table-column>
                    <el-table-column
                        prop="investTime"
                        label="投资时间"
                        align="center"
                        width="100px"
                        >
                        <template slot-scope="scope">
                            <el-input v-model="scope.row.investTime" :maxlength="100"></el-input>
                        </template>
                    </el-table-column>
                    <el-table-column
                        prop="investRound"
                        label="投资轮次"
                        align="center"
                        width="100px"
                        >
                        <template slot-scope="scope">
                            <el-input v-model="scope.row.investRound" :maxlength="100"></el-input>
                        </template>
                    </el-table-column>
                    <el-table-column
                        prop="collarVote"
                        label="是否领投"
                        align="center"
                        width="100px"
                        >
                        <template slot-scope="scope">
                            <el-input v-model="scope.row.collarVote" :maxlength="100"></el-input>
                        </template>
                    </el-table-column>
                    <el-table-column
                        prop="exitTime"
                        label="退出时间"
                        align="center"
                        width="100px"
                        >
                        <template slot-scope="scope">
                            <el-input v-model="scope.row.exitTime" :maxlength="100"></el-input>
                        </template>
                    </el-table-column>
                    <el-table-column
                        prop="exitMode"
                        label="退出方式"
                        align="center"
                        width="100px"
                        >
                        <template slot-scope="scope">
                            <el-input v-model="scope.row.exitMode" :maxlength="100"></el-input>
                        </template>
                    </el-table-column>
                    <el-table-column
                        prop="delegate"
                        label="是否委派董事监事"
                        align="center"
                        width="150px"
                        >
                        <template slot-scope="scope">
                            <el-input v-model="scope.row.delegate" :maxlength="100"></el-input>
                        </template>
                    </el-table-column>
                    <el-table-column
                        prop="holding"
                        label="初始持股比例"
                        width="120px"
                        align="center"
                        >
                        <template slot-scope="scope">
                            <el-input v-model="scope.row.holding" :maxlength="100"></el-input>
                        </template>
                    </el-table-column>
                    <el-table-column
                        prop="exitMoney"
                        label="退出金额</br>（万元）"
                        :render-header="renderTitle"
                        align="center"
                        width="100px"
                        >
                        <template slot-scope="scope">
                            <el-input type="number" v-model="scope.row.exitMoney"></el-input>
                        </template>
                    </el-table-column>
                    <el-table-column
                        prop="holdValue"
                        label="目前持有价值"
                        align="center"
                        width="120px"
                        >
                        <template slot-scope="scope">
                            <el-input type="number" v-model="scope.row.holdValue" :maxlength="100"></el-input>
                        </template>
                    </el-table-column>
                    <el-table-column
                        prop="irr"
                        label="IRR"
                        align="center"
                        width="80px"
                        >
                        <template slot-scope="scope">
                            <el-input v-model="scope.row.irr" :maxlength="100"></el-input>
                        </template>
                    </el-table-column>
                    <el-table-column
                        prop="participants"
                        label="主要参与人员"
                        align="center"
                        width="120px"
                        >
                        <template slot-scope="scope">
                            <el-input v-model="scope.row.participants" :maxlength="100"></el-input>
                        </template>
                    </el-table-column>
                    <el-table-column
                        prop="remarks"
                        label="备注"
                        align="center"
                        width="200px"
                        >
                        <template slot-scope="scope">
                            <el-input type="textarea" resize="none" :rows="2" v-model="scope.row.remarks" :maxlength="100"></el-input>
                        </template>
                    </el-table-column>
                    <el-table-column
                        align="center"
                        label="+"
                        label-class-name="add-button"
                        width="80px">
                        <template slot-scope="scope">
                            <div class="reduce-button" @click="delExecutive(scope.row.id,scope.$index)"><i class="el-icon-close"></i></div>
                        </template>
                    </el-table-column>
                </el-table>
            </el-form>
        </div>
    </div>
</template>
<script type="text/ecmascript-6">
    import {api} from '../../api';
    import {STATUS_HTTP_SUCCESS, apiHttp} from '__service/csHttp';
    export default {
        data() {
            return {
                executivesList: {
                    collarVote: '', // 是否领投
                    company: '', // 公司名称
                    delegate: '', // 是否委派董事监事
                    exitMode: '', // 退出方式
                    exitMoney: '', // 退出金额(万元)
                    exitTime: '', // 退出时间
                    fundId: this.$route.params.itemId, // 基金id
                    holdValue: '', // 目前持有价值
                    holding: '', // 初始持股比例
                    id: '', // 主id
                    industry: '', // 行业
                    investMoney: '', // 投资金额
                    investRound: '', // 投资轮次
                    investTime: '', // 投资时间
                    irr: '', // irr
                    itemId: '', // 项目名称
                    participants: '', // 主要参与人员
                    remarks: '', // 备注
                }, //信息列表
                itemInfo: {
                    fundData: [],
                },
            }
        },
        watch: {
        },
        props: {
        },
        mounted() {
            this.getInfo()
        },
        methods: {
            close() {
                this.$emit('close')
            },
            // 添加
            add(column) {
                if (column.labelClassName === 'add-button') {
                    this.itemInfo.fundData.push(Object.assign({}, this.executivesList));
                }
            },
            // 删除
            delExecutive(id,index) {
                let that = this
                this.$confirm('确定要删除此信息吗?', '提示', {
                    cancelButtonText: '取消',
                    confirmButtonText: '确定',
                    type: 'warning'
                }).then(function () {
                    //删除操作 DELETE_SAVEINFO
                    if (id) {
                        apiHttp(api.DELETE_SAVEINFO, {id: id}).then(ret => {
                            if (ret.resCode === STATUS_HTTP_SUCCESS) {
                                that.$message({
                                    message: '数据删除成功！',
                                    type: 'success',
                                    center: true
                                });
                                that.itemInfo.fundData.splice(index, 1)
                            }
                        })
                    } else {
                        that.itemInfo.fundData.splice(index, 1)
                        that.$message({
                            message: '数据删除成功！',
                            type: 'success',
                            center: true
                        });
                    }
                })
            },
            getInfo() {
                apiHttp(api.CHECK_CASEINFO, {id: this.$route.params.itemId}).then(ret=> {
                    if (ret.resCode === STATUS_HTTP_SUCCESS) {
                        this.itemInfo.fundData = ret.data
                    }
                })
            },
            save() {
                let flag = false;
                if (this.itemInfo.fundData.length > 0) {
                    this.itemInfo.fundData.map(item => {
                        if (!item.itemId) {
                            flag = false;
                            this.$message({
                                message: '请输入项目名称',
                                type: 'error',
                                center: true
                            });
                            return false;
                        } else {
                            flag = true;
                        }
                    })
                } else {
                    flag = true
                }
                if (flag) {
                    apiHttp(api.SAVE_CASEINFO, this.itemInfo.fundData).then(ret=> {
                        if (ret.resCode === STATUS_HTTP_SUCCESS) {
                            this.$message({
                                message: '修改成功！',
                                type: 'success',
                                center: true
                            });
                            this.$emit('update')
                        }
                    })
                }
            },
        },
        components: {
        },
    }
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
.el-right {
    float: right;
    margin-bottom: 15px;
}
.el-size {
    font-size: 30px;
}
.input-mid {
    display: table-cell;
    vertical-align: middle;
}
.btn-min {
    display: table-cell;
    vertical-align: middle;
    cursor: pointer;
}
table td{
    padding: 5px 5px;
    box-sizing: border-box;
}
.el-form-item {
    margin-bottom: 0px;
}
.ca-table th {
    line-height: 20px;
}
.el-delete {
    color: red;
}
.addBtn{
    color: red !important;
}
.el-icon-close {
    font-weight: bolder;
    font-size: 14px;
}
.ca-table-add-reduce .el-table .el-table__body .cell .reduce-button {
    margin: 0 auto;
}
</style>